'监控血量的健康组件'

extends Node
class_name HealthComponent

signal died#血量为0时发出
signal health_change#血量改变时发出

@export var max_health:float = 10#血量

var current_health = 0#当前血量

func _ready() -> void:
	current_health = max_health
	pass

#返回血量百分比
func get_health_percent() -> float:
	if max_health <= 0:
		return 1
	return min(current_health / max_health, 1)

#血量改变
func damage(damage_amount:float) -> void:
	current_health = clampf(current_health - damage_amount, 0, max_health)
	health_change.emit()
	if !current_health:
		died.emit()
	pass
